public class Sort {

    private static int index(int left, int right, int[] ints) {
        int index = ints[left];
        while (left < right) {
            while (ints[right] >= index && left < right) {
                right--;
            }
            ints[left] = ints[right];
            while (ints[left] <= index && left < right) {
                left++;
            }
            ints[right] = ints[left];
        }
        ints[right] = index;
        return right;
    }

    private static void sort(int left, int right, int[] ints) {
        if (left >= right)
            return;
        int index = index(left, right, ints);
        sort(left, index - 1, ints);
        sort(index + 1, right, ints);
    }

    public static void main(String[] args) {
        int[] ints = new int[] {2, 5, 8, 4, 6, 0, 1, 9, 3, 7};
        sort(0, ints.length - 1, ints);
        for (int i : ints) {
            System.out.print(ints[i] + ", ");
        }
    }
}
